<?php
/**
 * @author spenceryg
 * @date 2022/11/27
 * @time 12:21 上午
 * @focus love & life
 */


namespace app\auto\controller;


use app\common\lib\SpPinyin;
use app\common\lib\SpTranslate;
use ShaoZeMing\Translate\Exceptions\TranslateException;
use think\helper\Str;
use think\response\Json;

class Util extends \app\BaseController
{
    /**
     * getPinyin
     * @return Json
     */
    public function getPinyin(): Json
    {
        $word = input('word');
        return success('ok', SpPinyin::getAll($word));
    }

    /**
     * getPinyinFirst
     * @return Json
     */
    public function getPinyinFirst(): Json
    {
        $word = input('word');
        return success('ok', SpPinyin::getFirst($word));
    }

    /**
     * getChinese
     * @return Json
     * @throws TranslateException
     */
    public static function getChinese(): Json
    {
        $word = input('word');
        return success('ok', SpTranslate::getChinese($word));
    }

    /**
     * getEnglish
     * @return Json
     * @throws TranslateException
     */
    public function getEnglish(): Json
    {
        $word = input('word');
        return success('ok', SpTranslate::getEnglish($word));
    }


    /**
     * getEnglishWithType
     * @return Json
     * @throws TranslateException
     */
    public function getEnglishWithType(): Json
    {
        $word = input('word');
        return success('ok', SpTranslate::getEnglishWithType($word));
    }


    /**
     * 根据中文获取方法名
     * getMethodByComment
     */
    public function getMethodEnglish(): Json
    {
        $word = input('word');
        $res = SpTranslate::getEnglish($word);
        $res = Str::camel($res);
        return success('ok',$res);
    }


}
